<template>
  <div>
    <div class="el-form-item el-form-item--small el-form--label-top">
      <label class="el-form-item__label" style="padding: 0">自定义属性：</label>
      <div class="el-form-item__content">
        <monaco-editor v-model="params" height="300" :keyIndex="localData.prop" :options="options" />
      </div>
    </div>
    <div class="el-form-item el-form-item--small el-form--label-top">
      <label class="el-form-item__label" style="padding: 0">自定义事件：</label>
      <div class="el-form-item__content">
        <monaco-editor v-model="event" height="300" :keyIndex="localData.prop" :options="options" />
      </div>
    </div>
  </div>
</template>
<script>
import MonacoEditor from '../../utils2/monaco-editor'

export default {
  name: 'ConfigCustom',
  components: { MonacoEditor },
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      params: this.data.params || {},
      event: this.data.event || {},
      options: {
        fullScreen: true,
        minimap: {
          enabled: false
        }
      },
      localData: {}
    }
  },
  watch: {
    'localData.params'(val) {
      this.params = val || {}
    },
    'localData.event'(val) {
      this.event = val || {}
    },
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal)
      },
      deep: true
    },
    params(val) {
      try {
        this.localData.params = eval('(' + val + ')')
      } catch (e) {
        // console.error(e)
      }
    },
    event(val) {
      try {
        this.localData.event = eval('(' + val + ')')
      } catch (e) {
        // console.error(e)
      }
    }
  }
}
</script>
